﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion
{
    public class MultiLineCollisionData
    {
        private bool hasChanged;
        private Action<MultiLineCollisionData> collisionChangedAction;

        internal PhysicalData PhysicalData { get; private set; }
        public List<LineVector> InteresectedLines { get; private set; }

        public MultiLineCollisionData(PhysicalData physicalData, Action<MultiLineCollisionData> collisionChangedAction)
        {
            this.PhysicalData = physicalData;
            this.collisionChangedAction = collisionChangedAction;

            InteresectedLines = new List<LineVector>();
        }

        internal void NotifyIntersectionChanged()
        {
            if (hasChanged)
            {
                hasChanged = false;
                this.collisionChangedAction.Invoke(this);
            }
        }

        internal void AddLine(LineVector line)
        {
            if (!InteresectedLines.Contains(line))
            {
                InteresectedLines.Add(line);
                hasChanged = true;
            }
        }

        internal void RemoveLine(LineVector line)
        {
            if (InteresectedLines.Remove(line))
                hasChanged = true;
        }
    }
}
